/*********************************************************************************************  
* FUNCTION: fcn_calOldPwds  
* PURPOSE: Analyse old passwords of DDS user  
* NOTES:  
* CREATED: Nha Doan 11/10/2009  
* MODIFIED:   
  
'-------------------------------------------------------------------------------------------------*  
' Date       | Version | Ticket #    |       Author             | Description  
' ========== | ======= | =========== | =========================| ====================================================================  
'            |         |             |                          |   
'-------------------------------------------------------------------------------------------------*  
*/   
CREATE FUNCTION [dbo].[fcn_calOldPwds](@OldPwds varchar(1000),@NewPwd varchar(100))  
returns varchar(1000)  
begin  
 if @OldPwds is null set @OldPwds = ''  
 if @OldPwds = '' return @NewPwd  
 if len(@OldPwds) - len(replace(@OldPwds, '#', '')) < 3  
 begin  
  set @OldPwds =  @OldPwds +'#'+ @NewPwd  
 end  
 else  
 begin  
  set @OldPwds =  substring(@OldPwds,charindex('#',@OldPwds)+1,1000) + '#' + @NewPwd  
 end  
 return @OldPwds  
end
GO